﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace XNA.Common
{
	public class ModelData
	{
		#region CONSTRUCTION

		public ModelData (Model model, Texture2D texture, Effect effect, Matrix? setUp = null)
		{
			Model = model;
			SetUp = setUp ?? Matrix.Identity;

			Transforms = new Matrix[model.Bones.Count];
			Model.CopyAbsoluteBoneTransformsTo (Transforms);

			Texture = texture;

			foreach (var meshpart in Model.Meshes.SelectMany (x => x.MeshParts))
			{
				meshpart.Effect = effect.Clone ();
				meshpart.Effect.Parameters["xTexture"].SetValue (texture);
			}

		}
		
		#endregion

		#region PROPERTIES

		public Model Model
		{
			get;
			set;
		}

		public Matrix[] Transforms
		{
			get;
			set;
		}

		public Texture2D Texture
		{
			get;
			set;
		}

		public Matrix SetUp
		{
			get;
			set;
		}

		#endregion
	}
}
